package com.bwie.controller;

import com.bwie.bean.Accountant;
import com.bwie.bean.Type;
import com.bwie.service.AccountantService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class AccountantController {

    @Autowired
    AccountantService accountantService;
    @RequestMapping("list.do")
    public String list(
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
            Model model,
            String practice,
            String adateX,
            String adateD,
            String tid

    ){
        Map map = new HashMap();
        map.put("practice",practice);
        map.put("adateX",adateX);
        map.put("adateD",adateD);
        map.put("tid",tid);
        PageHelper.startPage(pageNum,3);
        List<Accountant>list=accountantService.list(map);
        PageInfo pageInfo = new PageInfo(list);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("map",map);
        return "list";
    }
    @RequestMapping("listType.do")
    @ResponseBody
    public List<Type>listType(){
        List<Type>listType=accountantService.listType();
        return listType;
    }
    @RequestMapping("toadd.do")
    public String toadd(){
        return "add";
    }
    @RequestMapping("add.do")
    @ResponseBody
    public Object add(Accountant accountant){
        int a=accountantService.addAcc(accountant);
        return a;
    }
    //
    @RequestMapping("delAll.do")
    @ResponseBody
    public Object delAll(String aid){
        int a=accountantService.delAll(aid);
        return a;
    }
}
